package game.common;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ProcessorStatManager {

	private static Logger logger = LoggerFactory.getLogger(ProcessorStatManager.class);

	static class SingletonHolder {
		static ProcessorStatManager instance = new ProcessorStatManager();
	}

	private Map<Integer, Long> startTimeCache = new ConcurrentHashMap<Integer, Long>();

	private Map<Integer, Integer> maxProcessorTimeCache = new ConcurrentHashMap<Integer, Integer>();

	public static ProcessorStatManager getInstance() {
		return SingletonHolder.instance;
	}

	public void startLog(int processorId, long startTime) {
		startTimeCache.put(processorId, startTime);
	}

	public void endStatLog(int processorId, long endTime) {
		Long startTime = startTimeCache.get(processorId);
		if (startTime != null) {
			int timeDiff = (int) (endTime - startTime);
			logger.warn("processor:{},cost={}ms", processorId, timeDiff);
			// logMaxTime(processorId,timeDiff);
			// Integer maxProcessorTime = maxProcessorTimeCache.get(processorId);

		}
	}

}
